<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
    <style>
        body {
            height: 8000px;
        }
    </style>
</head>

<body>
    <input type="text" id="username">
    <div class="text"></div>
    <script>
        const usernameIpt = document.getElementById('username')
        const textEle = document.querySelector('.text')
        //未节流
        /*
        onscroll = function (e) {
            console.log(e)
            //做一些复杂计算
        }
        */
        //节流
        /**/
        onscroll = _.throttle(function (e) {
            console.log(e)
            //做一些复杂计算
        }, 1000 )

        function write(){
            textEle.innerText = usernameIpt.value
        }

        usernameIpt.oninput = _.debounce(write, 500)
    </script>
</body>

</html>